<?php
/**
 * (exporter)
 */
namespace App\Exporter\Warehousing;

use App\Models\Inventory\Storage;
use App\Models\Product\ProductClassify;
use App\Util\User;
use Encore\Admin\Grid\Exporters\ExcelExporter;
use Maatwebsite\Excel\Concerns\WithMapping;
class StorageDetailExporter extends ExcelExporter implements WithMapping
{

    protected $fileName = '入库记录.csv';

    protected $headings = ['入库单','订单号','供应商','入库员','SKU','产品名称','季节性','品类','入库类型','入库数量','入库单价','包材单价',
        '不含税单价','入库金额','入库时间'];

    public function map($model) : array
    {
        return [
            $model->storage_no,
            $model->order_no ?: '',
            $model->storage->supplier->name ?? '',
            User::getUsernameById($model->storage->cuser_id ?? ''),
            $model->sku->psku_code ?? '',
            $model->sku->psku_cn ?? '',
            ProductClassify::$_season[$model->skuClassify->season ?? 3],
            $model->skuClassify->title ?? '',
            Storage::$_type[$model->storage->type ?? 4],
            $model->storage_num ?: 0,
            $model->unit_price ?: 0,
            $model->pack_price ?: 0,
            $model->unit_price_no_tax ?: 0,
            numberFormat(round(($model->storage_num ?: 0) * ($model->unit_price ?: 0),3)),
            $model->created_at,
        ];
    }
}
